package com.itsq.controller.resources;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itsq.common.bean.ErrorEnum;
import com.itsq.common.bean.Response;
import com.itsq.pojo.dto.GpsDto;
import com.itsq.pojo.dto.LocationServiceDto;
import com.itsq.pojo.dto.PageLocationDto;
import com.itsq.pojo.entity.Car;
import com.itsq.pojo.entity.Gps;
import com.itsq.pojo.entity.Personnel;
import com.itsq.service.resources.LocationService;
import com.itsq.token.CurrentUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 史先帅
 * @since 2021-01-29
 */

@RestController
@RequestMapping("/Location")
@AllArgsConstructor
@CrossOrigin
@Api(tags = "GPS模块")
public class LocationController {

    @Autowired
    private LocationService locationService;

    @GetMapping("login")
    @ApiOperation(value = "GPS模块单位登录", notes = "", httpMethod = "GET")
    public Response<Integer> loginSystem(){
        return Response.success(locationService.loginSystem());
    }

    @GetMapping("loginSystemUser")
    @ApiOperation(value = "GPS模块设备登录", notes = "", httpMethod = "GET")
    public Response<Integer> loginSystemUser(String loginName){
        return Response.success(locationService.loginSystemUser(loginName));
    }

    @GetMapping("bindGPS")
    @ApiOperation(value = "GPS模块设备绑定", notes = "", httpMethod = "GET")
    public Response<Integer> bindGPS(String macid,String platenumber,String fullName){
        return Response.success(locationService.bindGPS(macid,platenumber,fullName));
    }

    @GetMapping("getUserAndGpsInfoByIDsUtc")
    @ApiOperation(value = "查询单个设备GPS信息", notes = "", httpMethod = "GET")
    public Response<String> getUserAndGpsInfoByIDsUtc(String loginName){
        return Response.success(locationService.getUserAndGpsInfoByIDsUtc(loginName));
    }

    @PostMapping("selLocationPage")
    @ApiOperation(value = "GPS信息分页", notes = "", httpMethod = "GET")
    public Response<Page<Gps>> selLocationPage(@RequestBody PageLocationDto pageLocationDto){
        return Response.success(locationService.selLocationPage(pageLocationDto));
    }

    @PostMapping("update")
    @ApiOperation(value = "GPS信息模块修改", notes = "", httpMethod = "POST")
    public Response<Integer> update(@RequestBody Gps gps){
        return Response.success(locationService.update(gps));
    }

    @PostMapping("delete")
    @ApiOperation(value = "GPS信息模块删除", notes = "", httpMethod = "POST")
    public Response<Integer> delete(Integer id){
        return Response.success(locationService.delete(id));
    }
}
